package com.google.code.provadigital;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;

import com.google.code.provadigital.control.Controller;
import com.google.code.provadigital.model.Professor;

public class TelaCadastrarProfessor extends JFrame {

	private JPanel contentPane;
	private JTextField textCpf;
	private JTextField txtNome;
	private JTextField textLogin;
	private JTextField textSenha;

	/**
	 * Launch the application.
	 */

	/**
	 * Create the frame.
	 */
	public TelaCadastrarProfessor() {
		setTitle("Cadastro de Professor");
		setResizable(false);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 703, 467);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		contentPane.setLayout(new BorderLayout(0, 0));
		setContentPane(contentPane);

		JPanel panel = new JPanel();
		panel.setBackground(new Color(127, 255, 0));
		contentPane.add(panel, BorderLayout.CENTER);
		panel.setLayout(null);

		JLabel lblNome = new JLabel("Nome:");
		lblNome.setFont(new Font("Tahoma", Font.BOLD, 12));
		lblNome.setBounds(42, 199, 55, 14);
		panel.add(lblNome);

		textCpf = new JTextField();
		textCpf.setForeground(new Color(255, 255, 255));
		textCpf.setBackground(new Color(0, 0, 128));
		textCpf.setBounds(100, 231, 147, 20);
		panel.add(textCpf);
		textCpf.setColumns(10);

		txtNome = new JTextField();
		txtNome.setForeground(new Color(255, 255, 255));
		txtNome.setBackground(new Color(0, 0, 128));
		txtNome.setToolTipText("Digite seu nome aqui !");
		txtNome.setBounds(100, 197, 470, 20);
		panel.add(txtNome);
		txtNome.setColumns(10);

		JButton btnTelaPrincipal = new JButton("Tela Principal");
		btnTelaPrincipal.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				TelaPrincipal cl = new TelaPrincipal();

				cl.setVisible(true);
				dispose();
			}
		});
		btnTelaPrincipal.setForeground(new Color(0, 255, 0));
		btnTelaPrincipal.setBackground(new Color(0, 0, 128));
		btnTelaPrincipal.setBounds(503, 367, 115, 23);
		panel.add(btnTelaPrincipal);

		JLabel lblCpf = new JLabel("CPF:");
		lblCpf.setFont(new Font("Tahoma", Font.BOLD, 12));
		lblCpf.setBounds(52, 233, 26, 14);
		panel.add(lblCpf);

		JLabel label = new JLabel("");
		label.setBounds(434, 295, 46, 14);
		panel.add(label);

		JLabel lblNewLabel = new JLabel("");
		lblNewLabel
				.setIcon(new ImageIcon(
						"C:\\Users\\Eduardo\\Desktop\\PROVA DIGITAL\\PROVA DIGITAL long.png"));
		lblNewLabel.setBounds(33, 11, 618, 144);
		panel.add(lblNewLabel);

		JButton btnNewButton = new JButton("Salvar");
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				String nome = txtNome.getText();
				String cpf = textCpf.getText();
				String login = textLogin.getText();
				String senha = textSenha.getText();
				Professor p = new Professor();
				p.setNome(nome);
				p.setCpf(cpf);
				p.setLogin(login);
				p.setSenha(senha);
				Controller c = new Controller();
				c.inserirProfessor(p);

			}
		});
		btnNewButton.setFont(new Font("Tahoma", Font.BOLD, 11));
		btnNewButton.setForeground(new Color(0, 255, 0));
		btnNewButton.setBackground(new Color(0, 0, 128));
		btnNewButton.setBounds(32, 367, 89, 23);
		panel.add(btnNewButton);

		JButton btnNewButton_2 = new JButton("Remover");
		btnNewButton_2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				String nome = txtNome.getText();
				String cpf = textCpf.getText();
				Professor pr = new Professor();			
				
				pr.setNome("");
				pr.setCpf(cpf);
				Controller c = new Controller();
			    c.removerProfessor(pr);
							
								
			}
		});
		btnNewButton_2.setForeground(new Color(0, 255, 0));
		btnNewButton_2.setBackground(new Color(0, 0, 128));
		btnNewButton_2.setBounds(158, 367, 89, 23);
		panel.add(btnNewButton_2);

		JButton btnNewButton_3 = new JButton("Pesquisar");

		btnNewButton_3.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				String nome = txtNome.getText();
				String cpf = textCpf.getText();
				Professor pr = new Professor();			
				
				pr.setNome("");
				pr.setCpf(cpf);
				Controller c = new Controller();
				Professor p= c.buscarProfessor(pr);
				txtNome.setText(p.getNome());
				textCpf.setText(p.getCpf());
				
			}
		});

		btnNewButton_3.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				String nome = txtNome.getText();
				String cpf = textCpf.getText();
				Professor pr = new Professor();			
				
				pr.setNome("");
				pr.setCpf(cpf);
				Controller c = new Controller();
				Professor p= c.buscarProfessor(pr);
				txtNome.setText(p.getNome());
				textCpf.setText(p.getCpf());
				
			}
		});

		btnNewButton_3.setForeground(new Color(0, 255, 0));
		btnNewButton_3.setBackground(new Color(0, 0, 128));
		btnNewButton_3.setBounds(284, 367, 102, 23);
		panel.add(btnNewButton_3);

		JLabel lblLogin = new JLabel("Login:");
		lblLogin.setFont(new Font("Tahoma", Font.BOLD, 12));
		lblLogin.setBounds(42, 267, 46, 14);
		panel.add(lblLogin);

		textLogin = new JTextField();
		textLogin.setForeground(new Color(255, 255, 255));
		textLogin.setBackground(new Color(0, 0, 128));
		textLogin.setBounds(100, 265, 147, 20);
		panel.add(textLogin);
		textLogin.setColumns(10);

		JLabel lblNewLabel_1 = new JLabel("Senha:");
		lblNewLabel_1.setFont(new Font("Tahoma", Font.BOLD, 12));
		lblNewLabel_1.setBounds(42, 301, 46, 14);
		panel.add(lblNewLabel_1);

		textSenha = new JTextField();
		textSenha.setForeground(new Color(255, 255, 255));
		textSenha.setBackground(new Color(0, 0, 139));
		textSenha.setBounds(100, 299, 147, 20);
		panel.add(textSenha);
		textSenha.setColumns(10);
	}
}
